//package com.mmall.shiro;
//
//import com.caijinquan.admin.baseconfig.filter.FormAuthenticationCaptchaFilter;
//import org.apache.shiro.cache.ehcache.EhCacheManager;
//import org.apache.shiro.spring.LifecycleBeanPostProcessor;
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.servlet.Filter;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * <p>Shiro配置</p>
// *
// * @author lgongpeng
// * @company 财金圈（北京）金融服务外包有限公司@版权所有
// * @since 2016/11/24
// */
//@Configuration
//public class ShiroConfiguration {
//
//    private static Logger logger = LoggerFactory.getLogger(ShiroConfiguration.class);
//
//    /**
//     * shiro缓存管理器
//     *
//     * @return
//     */
//    @Bean
//    public EhCacheManager ehCacheManager() {
//        EhCacheManager em = new EhCacheManager();
//        em.setCacheManagerConfigFile("classpath:ehcache-shiro.xml");
//        logger.info("shiro缓存管理器");
//        return em;
//    }
//
//
//    @Bean(name = "myShiroRealm")
//    public MyShiroRealm myShiroRealm() {
//        MyShiroRealm realm = new MyShiroRealm();
//        logger.info("shiro的Realm");
//        return realm;
//    }
//
//    @Bean(name = "lifecycleBeanPostProcessor")
//    public LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
//        return new LifecycleBeanPostProcessor();
//    }
//
//    @Bean
//    public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
//        DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
//        daap.setProxyTargetClass(true);
//        return daap;
//    }
//
//    /**
//     * 安全管理器
//     *
//     * @return
//     */
//    @Bean(name = "securityManager")
//    public DefaultWebSecurityManager getDefaultWebSecurityManager(MyShiroRealm myShiroRealm) {
//        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
//
//        manager.setRealm(myShiroRealm);
//        manager.setCacheManager(ehCacheManager());
//        logger.info("shiro的安全管理器");
//        return manager;
//    }
//
//    @Bean
//    public AuthorizationAttributeSourceAdvisor getAuthorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager) {
//        AuthorizationAttributeSourceAdvisor aasa = new AuthorizationAttributeSourceAdvisor();
//        aasa.setSecurityManager(securityManager);
//        return aasa;
//    }
//
//    /**
//     * Shiro 的 Web 过滤器
//     *
//     * @return
//     */
//    @Bean(name = "shiroFilter")
//    public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager securityManager) {
//        ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
//
//        bean.setSecurityManager(securityManager);
//
//        // TODO: 2016/11/22 暂时写死
//        bean.setLoginUrl("/a/login");
//        bean.setSuccessUrl("/a");
//
//        Map<String, Filter> filters = new HashMap<>();
//        filters.put("authc", new FormAuthenticationCaptchaFilter());
//        bean.setFilters(filters);
//
//        //用户访问未对其授权的资源时，所显示的连接
//        bean.setUnauthorizedUrl("/error/403");
//
//        Map<String, String> filterChainDefinitionMap = new HashMap<String, String>();
//        logger.info("##################从数据库读取权限规则，加载到shiroFilter中##################");
//        logger.info("##################Shiro 的 Web 过滤器##################");
//
//        filterChainDefinitionMap.put("/static/**", "anon");//anon 可以理解为不拦截
//
//        filterChainDefinitionMap.put("/a/login", "authc");
//        filterChainDefinitionMap.put("/a/** ", "user");
//        filterChainDefinitionMap.put("/rest/**", "authcBasic");
//
//
//        bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
//        return bean;
//    }
//}
